const Joi = require('joi');

class NoticeValidate {
  async list(params) {
    const schema = Joi.object({
      title: Joi.string(),
      type: Joi.string(),
      content: Joi.string(),
      order: Joi.string().default('create_time'),
      method: Joi.string().default('desc'),
      pageIndex: Joi.string().default('1'),
      pageSize: Joi.string().default('10')
    })

    try {
      const value = await schema.validateAsync(params);

      return value
    } catch (error) {
      throw error
    }
  }


  async info(param) {
    const schema = Joi.object({
      id: Joi.string()
      .empty()
      .required()
      .message({
        'string.empty': '消息id不能为空',
        'string.required': '消息id为必填项'
      })
    })

    try {
      const value = await schema.validateAsync(param);

      return value
    } catch (error) {
      throw error
    }
  }


  async insert(param) {
    const schema = Joi.object({
      path: Joi.string()
      .empty()
      .required()
      .message({
        'string.empty': '消息来源不能为空',
        'string.required': '消息来源为必填项'
      }),

      msg: Joi.string()
      .empty()
      .required()
      .message({
        'string.empty': '消息内容不能为空',
        'string.required': '消息内容为必填项'
      })
    })

    try {
      const value = await schema.validateAsync(param);

      return value
    } catch (error) {
      throw error
    }
  }
}

module.exports = NoticeValidate